package com.liu.netty;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component
@Slf4j
@ChannelHandler.Sharable
public class ServerHanlderUp extends SimpleChannelInboundHandler<String> {

    @Value("${netty.port}")
    private Integer port;

    @Value("${netty.name}")
    private String name;

    @Override
    protected void messageReceived(ChannelHandlerContext context, String s) throws Exception {

        log.info("{}[:{}]}: 接受到的消息为{}\r\n", name,  port, s);
        context.writeAndFlush(String.format("456: sent from %s[:%s]", name, port));
    }
}
